package com.suse.jd_system_server.controller;

import com.suse.jd_system_server.service.LoginService;
import com.suse.jd_system_server.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/General")
@CrossOrigin
public class ShbGeneralController {

    @Autowired
    private LoginService loginService;

    /**
     * 登录
     * @param param
     * @return
     */
    @PostMapping("login")
    public Result login(@RequestBody Map param){
        return loginService.Login(param.get("username").toString(), param.get("password").toString());
    }

    /**
     * 退出登录
     * @param userId
     * @return
     */
    @GetMapping("logout")
    public Result logout(Long userId) {
        return loginService.Logout(userId);
    }

    /**
     * 注册
     * @param param
     * @return
     */
    @PostMapping("/register")
    public Result register(@RequestBody Map param){
        return loginService.Register(param);
    }
    /**
     * 查询角色对应权限
     * @param role_id
     * @return
     */
    @GetMapping("/selectRoles/{role_id}")
    public Result selectRoles(@PathVariable(value = "role_id")Long role_id){
        return Result.buildSuccess(loginService.selectRoles(role_id));
    }
    /**
     * 查询所有权限
     * @return
     */
    @GetMapping("/selectallAuthority")
    public Result selectallAuthority(){
        return Result.buildSuccess(loginService.selectallAuthority());
    }
    /**
     * 删除角色对应权限
     * @param param
     * @return
     */
    @PostMapping("/deleteau")
    public Result deleteau(@RequestBody Map param){
        loginService.deleteau(param);
        return Result.buildSuccess();
    }

    /**
     * 查询省份
     * @return
     */
    @GetMapping("/selectProvince")
    public Result selectProvince(){
        return Result.buildSuccess(loginService.selectProvince());
    }
    /**
     * 查询城市
     * @return
     */
    @GetMapping("/selectCity")
    public Result selectCity(String cityName){
        return Result.buildSuccess(loginService.selectCity(cityName));
    }
}
